package com.qf.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 你的名字
 * @Date: 2021/07/06/17:37
 * @Description:
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private static final String SUCCESS = "success";
    private static final String ERROR = "error";

    private String status; // 表示请求是否成功成功

    private String msg; // 如果请求失败，失败原因

    private T data; // 响应的数据

    public static Result success(){
        return new Result(SUCCESS,null,null);
    }
    public static Result success(Object data){
        return new Result(SUCCESS,null,data);
    }
    public static Result error(String msg){
        return new Result(ERROR,null,null);
    }
    //公共响应的方法
    public static Result write(Object target){
        if(target instanceof  Boolean) {
            boolean flag= (boolean) target;
            if(flag){
                return success();
            }else {
                return error("操作失败");
            }
        }
        return error(null);
    }
    public static Result write(Object target,Object data){
        if(target instanceof  Boolean) {
            boolean flag= (boolean) target;
            if(flag){
                return success(data);
            }else {
                return error("操作失败");
            }
        }
        return error(null);
    }
}


